<template>
  <div class="app-container">
    <!-- <el-tree :data="typeList" :show-overflow-tooltip="true" node-key="id" @node-click="nodeClick" v-loading="loading" default-expand-all
      :expand-on-click-node="false" style="font-size:12px;width:300px">
    </el-tree> -->
    <el-scrollbar style="height:478px;width:204px">
      <el-tree :data="typeList" :show-overflow-tooltip="true" node-key="id" @node-click="nodeClick" v-loading="loading"
        default-expand-all :expand-on-click-node="false" style="font-size:12px;width:400px;"
        highlight-current></el-tree>
    </el-scrollbar>
  </div>
</template>

<script>
import { listFileTree, addInformation, updateInformation } from "@/api/file/information";
import { id } from "@/api/system/UUID";
import { listFileTreeExternal } from "@/api/file/external";
import { listFileTreeInternal } from "@/api/file/internal";
export default {
  name: "File",
  props: {
    typeCode: {
      type: [String, Number],
      default: ""
    },
    isTree: {
      type: Boolean,
      default: true
    },
    fileType: {
      type: [String, Number],
      default: ""
    },
  },
  data() {

    return {

      // 遮罩层
      loading: true,
      id: 1,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,

      // 主分类表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        name: null,
        typeCode: null,
        parentId: null,
        idPath: null,
        orderIndex: null,
        fullIndex: null,
        opId: null,
        opName: null,
        deptId: null,
        deptName: null,
        opTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        opTime: [
          { required: true, message: "操作时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    nodeClick(data) {
      this.$emit('getNode', data);
    },
    /** 查询主分类列表 */
    getList() {
      //this.queryParams.typeCode = this.typeCode
      this.loading = true;
      if (this.fileType == "1") { //文件柜
        listFileTree(this.queryParams).then(response => {
          this.typeList = response.data;
          this.loading = false;
        });
      } else if (this.fileType == "2") {//外部文件柜
        listFileTreeExternal(this.queryParams).then(response => {
          this.typeList = response.data;
          this.loading = false;
        });
      } else {//内部文件柜
        listFileTreeInternal(this.queryParams).then(response => {
          this.typeList = response.data;
          this.loading = false;
        });
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        typeCode: null,
        parentId: null,
        idPath: null,
        orderIndex: null,
        fullIndex: null,
        opId: null,
        opName: null,
        deptId: null,
        deptName: null,
        opTime: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加主分类";
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addType(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  padding-right: 8px;
}

// 最顶层添加图标
.el-tree ::v-deep .el-tree-node__content .el-tree-node__label {
  color: black;
  padding-left: 22px;
  background: url("../../images/01.png") no-repeat 0 3px;
  background-size: 13px 13px;
}

// 展开第二级节点
.el-tree ::v-deep .el-tree-node__children .el-tree-node__label {
  padding-left: 22px;
  background: url("../../images/01.png") no-repeat 0 3px;
  background-size: 13px 13px;
}

//第三级节点
.el-tree ::v-deep .el-tree-node__children .el-tree-node__children .el-tree-node__label {
  padding-left: 22px;
  background: url("../../images/02.png") no-repeat 0 3px;
  background-size: 13px 13px;
}
</style>
